//
//  ControlCell.m
//  CommandPattern
//
//  Created by 颖 on 2017/11/28.
//  Copyright © 2017年 SUIRUI. All rights reserved.
//

#import "ControlCell.h"

@interface ControlCell ()

@property (weak, nonatomic) IBOutlet UILabel *slot;

@property (nonatomic, strong) id<Command> onCommand;

@property (nonatomic, strong) id<Command> offCommand;

@end

@implementation ControlCell

- (instancetype)init{
    self = [super init];
    if (self) {
        self = [[[NSBundle mainBundle] loadNibNamed:@"ControlCell.xib" owner:self options:nil] firstObject]; ;
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setOnCommand:(id<Command>)onCommand offCommand:(id<Command>)offCommand slotName:(NSString *)name{
    _onCommand = onCommand;
    _offCommand = offCommand;
    _slot.text = name;
}

- (IBAction)appliancesOn:(id)sender {
    [_onCommand execute];
}

- (IBAction)appliancesOff:(id)sender {
    [_offCommand execute];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
